﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using VietKinsNutrition.Data;
using VietKinsNutrition.Bussiness;

namespace VietKinsNutrition.UserControl
{
    public partial class Frm_Tonghopkhauphan : DevExpress.XtraEditors.XtraUserControl
    {
        private int _Option;
        private DateTime FromDate, FinishDate;
        //ClsTblDiemdanhtreanBLL ClsTblDiemdanhtreanbll = new ClsTblDiemdanhtreanBLL();
        ClsEventsInControlBLL ClsEventsInControlbll = new ClsEventsInControlBLL();
        ClsKhauphandinhduongtrongtuanBLL ClsKhauphandinhduongtrongtuan_bll;

        public Frm_Tonghopkhauphan()
        {
            InitializeComponent();
            ClsKhauphandinhduongtrongtuan_bll = new ClsKhauphandinhduongtrongtuanBLL();
            datTu.EditValue = DateTime.Now;
            datDen.EditValue = DateTime.Now;
            try
            {
                ClsKhauphandinhduongtrongtuan_bll.GetMonth(datTu.DateTime, this.grdThongke, this.dataGridView1);
                ClsKhauphandinhduongtrongtuan_bll.GridView = this.dataGridView2;
            }
            catch { }
        }

        private void Frm_Tonghopkhauphan_Load(object sender, EventArgs e)
        {
            ClsKhauphandinhduongtrongtuan_bll.FillDataBase(grdThongke, grdTonghop);
            this.lbTongXuat.Text = ClsKhauphandinhduongtrongtuan_bll.TongSoTre.ToString();
        }

        private void datTu_EditValueChanged(object sender, EventArgs e)
        {
            ClsKhauphandinhduongtrongtuan_bll = new ClsKhauphandinhduongtrongtuanBLL();
            if (datTu.DateTime < datDen.DateTime)
            {
                ClsKhauphandinhduongtrongtuan_bll.GetMonth(datTu.DateTime, datDen.DateTime, this.grdThongke, this.dataGridView1);
            }
            else if (datTu.DateTime == datDen.DateTime)
            {
                ClsKhauphandinhduongtrongtuan_bll.GetMonth(datTu.DateTime, this.grdThongke, this.dataGridView1);
            }
            else
                return;
            ClsKhauphandinhduongtrongtuan_bll.GridView = this.dataGridView2;
            Frm_Tonghopkhauphan_Load(sender, e);
        }

        private void datDen_EditValueChanged(object sender, EventArgs e)
        {
            datTu_EditValueChanged(sender, e);
        }

        public string sTenso, sTenphong, sTentruong;
        public string[] s = new string[100];
        private void btnIn_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = grdThongke.GridControl.DataSource;
            dataGridView2.DataSource = grdTonghop.GridControl.DataSource;
            if (this.dataGridView1.RowCount == 0)
            {
                MessageBox.Show(" Bạn không thể in khi nội dung hóa đơn trống ", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //  ClsKhauphandinhduongtrongtuan_bll.ExportFileExel(this.dataGridView1, this.saveFileDialog1, ClsKhauphandinhduongtrongtuan_bll.FinishDay);
            ClsTblTruonghocBLL ClsTblTruonghocbll = new ClsTblTruonghocBLL();
            DataTable Tbl = ClsTblTruonghocbll.ReturnTblTRuong();
            if (Tbl.Rows.Count > 0)
            {
                DataRow dr = Tbl.Rows[0];
                sTenso = dr["TensoGD"].ToString();
                sTentruong = dr["Tentruong"].ToString();
                sTenphong = dr["TenphongGD"].ToString();
            }
            for (int i = 0; i <= 5; i++)
            {
                s[i] = dataGridView1.Columns[i + 3].HeaderText.ToString();
            }

            DataTable tg = (DataTable)(dataGridView1.DataSource);
            System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("VietKinsNutrition.Resources." + "bang tong hop dinh duong trong tuan.xls");
            ClsDanhsachNV.baocaotuan(stream, "bang tong hop dinh duong trong tuan.xls", sTenso, sTenphong, sTentruong, "", dataGridView1, dataGridView2, s);
        }
    }
}
